package com.biostime.rpc.terminal.util;

import org.hibernate.Criteria;
import org.hibernate.sql.JoinType;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 说明
 * </p>
 *
 * @author yangrzh 2014/8/6
 */
public class AliasUtil {

    private Map<String, Integer> aliasMap;

    public AliasUtil() {
        aliasMap = new HashMap<String, Integer>();
    }

    public boolean exist(String path) {
        if (aliasMap.get(path) == null) {
            return false;
        }
        return true;
    }

    public boolean notExist(String path) {
        return !exist(path);
    }

    public void set(String path) {
        aliasMap.put(path, 1);
    }

    public void createAlias(String path, final Criteria criteria) {
        if (notExist(path)) {
            criteria.createAlias(path, path);
            set(path);
        }
    }

    public void createAlias(String path, final Criteria criteria, JoinType joinType) {
        if (notExist(path)) {
            criteria.createAlias(path, path, joinType);
            set(path);
        }
    }

    public void createAlias(String path, String pre, final Criteria criteria, JoinType joinType) {
        if (notExist(path)) {
            criteria.createAlias(path, pre, joinType);
            set(path);
        }
    }

}
